import {create as createService} from '@/services/topic'
import {history} from 'umi'
import {message} from 'antd'

//  文章新增
const namespace = 'createTopic';
const selectState = state => state[namespace];
const Model = {
  namespace,
  state: {
    title: '',
    content: '',
    user: ''
  },
  effects: {
    * create(_, {call, select}) {
      const state = yield select(selectState);
      // eslint-disable-next-line no-console
      console.log(state);
      const result = yield call(createService, state);
      if (result.code === 200) {
        message.success(result.msg);
        history.push('/')
      } else {
        message.error(result.msg)
      }
    },
  },
  reducers: {
    overrideStateProps(state, {payload}) {
      return {
        ...state,
        ...payload,
      }
    }
  }
};

export default Model





